package cuongnh.project.japanesediary.vocabulary.ui.wizard.page;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.layout.GridData;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.wb.swt.ResourceManager;

import cuongnh.project.japanesediary.vocabulary.model.Vocabulary;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.beans.PojoProperties;

public class NewVocabularyWizardPage extends WizardPage {
	private DataBindingContext m_bindingContext;
	private final FormToolkit toolkit = new FormToolkit(Display.getDefault());
	private Vocabulary vocabulary;
	private Text txtVocabulary;
	private Text txtFurigana;
	private Text txtHanViet;
	private Text txtVietnameseMeaning;
	private Text txtEnglishMeaning;
	private Text txtJapaneseMeaning;
	private Text txtVietnameseUsage;
	private Text txtEnglishUsage;
	private Text txtJapaneseUsage;

	/**
	 * Create the wizard.
	 */
	public NewVocabularyWizardPage(Vocabulary vocabulary) {
		super("wizardPage");
		setTitle("Create a new Vocabulary wizard page");
		setDescription("Create a new vocabulary screen.");
		this.vocabulary = vocabulary;
	}

	/**
	 * Create contents of the wizard.
	 * @param parent
	 */
	public void createControl(Composite parent) {
		parent.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		Composite container = new Composite(parent, SWT.NULL);
		container.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		setControl(container);
		container.setLayout(new GridLayout(2, false));

		Group grpVocabulary = new Group(container, SWT.NONE);
		GridData gd_grpVocabulary = new GridData(SWT.FILL, SWT.FILL, false,
				false, 1, 1);
		gd_grpVocabulary.heightHint = 134;
		grpVocabulary.setLayoutData(gd_grpVocabulary);
		grpVocabulary.setText("Vocabulary");
		toolkit.adapt(grpVocabulary);
		toolkit.paintBordersFor(grpVocabulary);
		grpVocabulary.setLayout(new GridLayout(3, false));

		txtVocabulary = new Text(grpVocabulary, SWT.BORDER | SWT.CENTER);
		txtVocabulary.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		txtVocabulary.setFont(SWTResourceManager.getFont("Segoe UI", 24,
				SWT.BOLD));
		txtVocabulary.setBackground(SWTResourceManager.getColor(240, 128, 128));
		GridData gd_txtVocabulary = new GridData(SWT.FILL, SWT.CENTER, true,
				false, 3, 1);
		gd_txtVocabulary.widthHint = 219;
		gd_txtVocabulary.heightHint = 49;
		txtVocabulary.setLayoutData(gd_txtVocabulary);

		Label lblFurigana = new Label(grpVocabulary, SWT.NONE);
		lblFurigana.setAlignment(SWT.CENTER);
		lblFurigana.setForeground(SWTResourceManager.getColor(255, 255, 0));
		lblFurigana.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.BOLD));
		GridData gd_lblFurigana = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
		gd_lblFurigana.widthHint = 67;
		lblFurigana.setLayoutData(gd_lblFurigana);
		lblFurigana.setBackground(SWTResourceManager.getColor(105, 105, 105));
		lblFurigana.setText("Furigana");

		txtFurigana = new Text(grpVocabulary, SWT.BORDER | SWT.MULTI);
		txtFurigana.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
		txtFurigana.setFont(SWTResourceManager
				.getFont("Segoe UI", 12, SWT.BOLD));
		GridData gd_txtFurigana = new GridData(SWT.FILL, SWT.FILL, false,
				false, 2, 1);
		gd_txtFurigana.heightHint = 23;
		txtFurigana.setLayoutData(gd_txtFurigana);

		Label lblHanViet = new Label(grpVocabulary, SWT.NONE);
		lblHanViet.setAlignment(SWT.CENTER);
		lblHanViet.setForeground(SWTResourceManager.getColor(255, 255, 0));
		lblHanViet.setBackground(SWTResourceManager.getColor(105, 105, 105));
		lblHanViet.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.BOLD));
		lblHanViet.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		lblHanViet.setText("HAN-VIET");

		txtHanViet = new Text(grpVocabulary, SWT.BORDER | SWT.MULTI);
		txtHanViet.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
		txtHanViet
				.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.BOLD));
		txtHanViet.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 2, 1));

		Group grpUsage = new Group(container, SWT.NONE);
		grpUsage.setText("Usage");
		GridData gd_grpUsage = new GridData(SWT.FILL, SWT.FILL, true, true, 1,
				2);
		gd_grpUsage.heightHint = 192;
		grpUsage.setLayoutData(gd_grpUsage);
		toolkit.adapt(grpUsage);
		toolkit.paintBordersFor(grpUsage);
		grpUsage.setLayout(new GridLayout(1, false));

		TabFolder tabUsage = new TabFolder(grpUsage, SWT.NONE);
		GridData gd_tabUsage = new GridData(SWT.FILL, SWT.FILL, true, true, 1,
				2);
		gd_tabUsage.widthHint = 540;
		tabUsage.setLayoutData(gd_tabUsage);
		toolkit.adapt(tabUsage);
		toolkit.paintBordersFor(tabUsage);

		TabItem tbtmVietnameseUsage = new TabItem(tabUsage, SWT.NONE);
		tbtmVietnameseUsage.setImage(ResourceManager
				.getPluginImage("cuongnh.project.japanesediary.vocabulary",
						"icons/vietnam.jpg"));
		tbtmVietnameseUsage.setText("Vietnamese");

		txtVietnameseUsage = new Text(tabUsage, SWT.BORDER | SWT.WRAP
				| SWT.V_SCROLL | SWT.MULTI);
		tbtmVietnameseUsage.setControl(txtVietnameseUsage);

		TabItem tbtmEnglishUsage = new TabItem(tabUsage, SWT.NONE);
		tbtmEnglishUsage.setImage(ResourceManager
				.getPluginImage("cuongnh.project.japanesediary.vocabulary",
						"icons/england.jpg"));
		tbtmEnglishUsage.setText("English");

		txtEnglishUsage = new Text(tabUsage, SWT.BORDER | SWT.WRAP
				| SWT.V_SCROLL | SWT.MULTI);
		tbtmEnglishUsage.setControl(txtEnglishUsage);

		TabItem tbtmJapaneseUsage = new TabItem(tabUsage, SWT.NONE);
		tbtmJapaneseUsage.setImage(ResourceManager.getPluginImage(
				"cuongnh.project.japanesediary.vocabulary", "icons/japan.jpg"));
		tbtmJapaneseUsage.setText("Japanese");

		txtJapaneseUsage = new Text(tabUsage, SWT.BORDER | SWT.WRAP
				| SWT.V_SCROLL | SWT.MULTI);
		tbtmJapaneseUsage.setControl(txtJapaneseUsage);
		// toolkit.paintBordersFor(table);

		Group grpMeaning = new Group(container, SWT.NONE);
		GridData gd_grpMeaning = new GridData(SWT.FILL, SWT.FILL, true, false,
				1, 1);
		gd_grpMeaning.widthHint = 300;
		grpMeaning.setLayoutData(gd_grpMeaning);
		grpMeaning.setText("Meaning");
		toolkit.adapt(grpMeaning);
		toolkit.paintBordersFor(grpMeaning);
		grpMeaning.setLayout(new GridLayout(1, false));

		TabFolder tabMeaning = new TabFolder(grpMeaning, SWT.NONE);
		GridData gd_tabMeaning = new GridData(SWT.FILL, SWT.FILL, true, true,
				1, 1);
		gd_tabMeaning.heightHint = 144;
		tabMeaning.setLayoutData(gd_tabMeaning);
		tabMeaning.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		toolkit.adapt(tabMeaning);
		toolkit.paintBordersFor(tabMeaning);

		TabItem tbtmVietnameseMeaning = new TabItem(tabMeaning, SWT.NONE);
		tbtmVietnameseMeaning.setImage(ResourceManager
				.getPluginImage("cuongnh.project.japanesediary.vocabulary",
						"icons/vietnam.jpg"));
		tbtmVietnameseMeaning.setText("Vietnamese");

		txtVietnameseMeaning = new Text(tabMeaning, SWT.BORDER | SWT.WRAP
				| SWT.V_SCROLL | SWT.MULTI);
		tbtmVietnameseMeaning.setControl(txtVietnameseMeaning);

		TabItem tbtmEnglishMeaning = new TabItem(tabMeaning, SWT.NONE);
		tbtmEnglishMeaning.setImage(ResourceManager
				.getPluginImage("cuongnh.project.japanesediary.vocabulary",
						"icons/england.jpg"));
		tbtmEnglishMeaning.setText("English");

		txtEnglishMeaning = new Text(tabMeaning, SWT.BORDER | SWT.WRAP
				| SWT.V_SCROLL | SWT.MULTI);
		tbtmEnglishMeaning.setControl(txtEnglishMeaning);

		TabItem tbtmJapaneseMeaning = new TabItem(tabMeaning, SWT.NONE);
		tbtmJapaneseMeaning.setImage(ResourceManager.getPluginImage(
				"cuongnh.project.japanesediary.vocabulary", "icons/japan.jpg"));
		tbtmJapaneseMeaning.setText("Japanese");

		txtJapaneseMeaning = new Text(tabMeaning, SWT.BORDER | SWT.WRAP
				| SWT.V_SCROLL | SWT.MULTI);
		tbtmJapaneseMeaning.setControl(txtJapaneseMeaning);
		m_bindingContext = initDataBindings();
	}
	protected DataBindingContext initDataBindings() {
		DataBindingContext bindingContext = new DataBindingContext();
		//
		IObservableValue observeTextTextObserveWidget = WidgetProperties.text(
				SWT.Modify).observe(txtVocabulary);
		IObservableValue vocabularyVocabularyObserveValue = PojoProperties
				.value("vocabulary").observe(vocabulary);
		bindingContext.bindValue(observeTextTextObserveWidget,
				vocabularyVocabularyObserveValue, null, null);
		//
		IObservableValue observeTextText_1ObserveWidget_1 = WidgetProperties
				.text(SWT.Modify).observe(txtFurigana);
		IObservableValue furiganaVocabularyObserveValue = PojoProperties.value(
				"furigana").observe(vocabulary);
		bindingContext.bindValue(observeTextText_1ObserveWidget_1,
				furiganaVocabularyObserveValue, null, null);
		//
		IObservableValue observeTextTxtHanVietObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtHanViet);
		IObservableValue hanvietVocabularyObserveValue = PojoProperties.value(
				"hanviet").observe(vocabulary);
		bindingContext.bindValue(observeTextTxtHanVietObserveWidget,
				hanvietVocabularyObserveValue, null, null);
		//
		IObservableValue observeTextTxtVietnameseMeaningObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtVietnameseMeaning);
		IObservableValue vnMeaningVocabularyObserveValue = PojoProperties
				.value("vnMeaning").observe(vocabulary);
		bindingContext.bindValue(observeTextTxtVietnameseMeaningObserveWidget,
				vnMeaningVocabularyObserveValue, null, null);
		//
		IObservableValue observeTextTxtEnglishMeaningObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtEnglishMeaning);
		IObservableValue enMeaningVocabularyObserveValue = PojoProperties
				.value("enMeaning").observe(vocabulary);
		bindingContext.bindValue(observeTextTxtEnglishMeaningObserveWidget,
				enMeaningVocabularyObserveValue, null, null);
		//
		IObservableValue observeTextTxtJapaneseMeaningObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtJapaneseMeaning);
		IObservableValue jpMeaningVocabularyObserveValue = PojoProperties
				.value("jpMeaning").observe(vocabulary);
		bindingContext.bindValue(observeTextTxtJapaneseMeaningObserveWidget,
				jpMeaningVocabularyObserveValue, null, null);
		//
		IObservableValue observeTextTxtVietnameseUsageObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtVietnameseUsage);
		IObservableValue vnUsageVocabularyObserveValue = PojoProperties.value(
				"vnUsage").observe(vocabulary);
		bindingContext.bindValue(observeTextTxtVietnameseUsageObserveWidget,
				vnUsageVocabularyObserveValue, null, null);
		//
		IObservableValue observeTextTxtEnglishUsageObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtEnglishUsage);
		IObservableValue enUsageVocabularyObserveValue = PojoProperties.value(
				"enUsage").observe(vocabulary);
		bindingContext.bindValue(observeTextTxtEnglishUsageObserveWidget,
				enUsageVocabularyObserveValue, null, null);
		//
		IObservableValue observeTextTxtJapaneseUsageObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtJapaneseUsage);
		IObservableValue jpUsageVocabularyObserveValue = PojoProperties.value(
				"jpUsage").observe(vocabulary);
		bindingContext.bindValue(observeTextTxtJapaneseUsageObserveWidget,
				jpUsageVocabularyObserveValue, null, null);
		//
		return bindingContext;
	}
}
